package com.joycessh.service.impl;

import org.hibernate.HibernateException;

import com.joycessh.PO.user.UserPO;
import com.joycessh.VO.user.LoginVO;
import com.joycessh.VO.user.RegisterVO;
import com.joycessh.dao.IUserDao;
import com.joycessh.dao.impl.UserDaoImpl;
import com.joycessh.service.IUserService;

public class UserServiceImpl implements IUserService {
	
	private UserPO userpo;
	private IUserDao userDao;
	
	public UserServiceImpl() {
		userDao = new UserDaoImpl();
	}

	@Override
	public boolean userLogin(LoginVO loginvo) {
		// TODO Auto-generated method stub
		boolean flag = false;
		try {
			if(userDao.checkUser(loginvo.getUserId(), loginvo.getPassword())) {
				flag = true;
			}			
		}catch(HibernateException e) {
			e.printStackTrace();		
		}
		return flag;	
	}

	@Override
	public boolean userRegister(RegisterVO registervo) {
		// TODO Auto-generated method stub
		boolean flag =false;
		userpo = new UserPO();
		userpo.setUserId(registervo.getUserId());
		userpo.setUsername(registervo.getUsername());
		userpo.setPassword(registervo.getPassword());
		
		try {
			if(userDao.saveUser(userpo)) {
				flag = true;
			}	
		}catch(HibernateException hbe) {
			hbe.printStackTrace();
		}
		return flag;
	}
	

}
